//------------------------------------------------------------------------------
// <copyright file="DispatcherExtension.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Windows.Threading;

namespace DAnton.Utilities.Extensions
{
    public static class DispatcherExtension
    {
        public static void InvokeIfNeeded(this DispatcherObject dispatcher, 
                                          Action action,
                                          DispatcherPriority priority)
        {
            if (Thread.CurrentThread != dispatcher.Dispatcher.Thread)
                dispatcher.Dispatcher.Invoke(action, priority);
            else
                action();
        }

        public static void InvokeIfNeeded(this DispatcherObject dispatcher,
                                  Action action)
        {
            if (Thread.CurrentThread != dispatcher.Dispatcher.Thread)
                dispatcher.Dispatcher.Invoke(action);
            else
                action();
        }
    }
}
